package com.list;
//存储学生对象并遍历：创建一个存储学生对象的集合，存储3个学生对象，实用程序实现在控制台遍历该集合
import com.domain.Student;

import java.util.ArrayList;

public class StudentTest01 {
    public static void main(String[] args) {
        /*getArrayList<String> list = new getArrayList<>();
        Student02 stu = new Student02();
        System.out.println(list);*/
        //错误代码

        //创建集合对象
        ArrayList<Student> list = new ArrayList<>();

        //创建学生对象
        Student stu1 = new Student("张三",23);
        Student stu2 = new Student("李四",24);
        Student stu3 = new Student("王五",25);

        //添加学生对象到集合中
        list.add(stu1);
        list.add(stu2);
        list.add(stu3);

        //遍历集合
        for (int i = 0; i < list.size(); i++) {
            Student stu = list.get(i);
            System.out.println(stu);//集合存储的为对象对应的内存地址
            String name = stu.getName();
            int age = stu.getAge();
            System.out.println(name + "  " + age);
        }
    }
}
